//1、通用字符串
let arr = "abcdefghigklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

//2、根据选择器获得指定的元素数组
let $ = (t) => {
    return document.querySelectorAll(t);
};

//3、产生随机验证码
function getRandomCode() {
    let st = "";
    st += arr[Math.floor(Math.random() * (52))];
    for (let i = 0; i < 5; i++) {
        let index = Math.floor(Math.random() * (arr.length));
        st += arr.charAt(index);
    }
    return st;
}

// 4、存放定时函数编号的数组
let arrNum = [];


//5、获得当前元素的后面第几个兄弟元素
function getNextESBL(e, n) {
    if (e === undefined) {
        return null;
    }
    if (n === undefined) {
        n = 0;
    }
    while (1) {
        if (n <= 0) {
            break;
        }
        e = e.nextElementSibling;
        if (e === undefined || e === null) {
            break;
        }
        n--;
    }
    return e;
}

//6、获得当前元素的前面第几个兄弟元素
function getPreviousESBL(e, n) {
    if (e === undefined) {
        return null;
    }
    if (n === undefined) {
        n = 0;
    }
    while (1) {
        if (n <= 0) {
            break;
        }
        e = e.previousElementSibling;
        if (e === undefined || e === null) {
            break;
        }
        n--;
    }
    return e;
}

//7、获得当前元素的前面第几层父级元素
function getParentElement(e, n) {
    if (e === undefined) {
        return null;
    }
    if (n === undefined) {
        n = 0;
    }
    while (1) {
        if (n <= 0) {
            break;
        }
        e = e.parentNode;
        if (e === undefined || e === null) {
            break;
        }
        n--;
    }
    return e;
}


//8、获得随机的分数  手机号
let getRandomTel = () => {
    let s = [3, 5, 6, 7, 8, 9];
    let l = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
    let st = 1 + ""
        + s[Math.floor(Math.random() * s.length)];
    for (let i = 0; i < 9; i++) {
        st += l[Math.floor(Math.random() * l.length)];
    }
    return st;
};

//9、获得随机的生日：1994-2001 1-12 1-31
let getRandomBirthday = () => {
    let year = Math.floor(Math.random() * (2001 - 1994 + 1)) + 1994;
    let month = Math.floor(Math.random() * (12 - 1 + 1)) + 1;
    let max = -1;
    if (month === 4 || month === 6 || month === 11 || month === 9) {
        max = 30;
    } else if (month === 2) {
        //判断闰年
        if ((year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0)) {
            max = 29;
        } else {
            max = 28;
        }
    } else {
        max = 31;
    }
    let date = Math.floor(Math.random() * (max - 1 + 1)) + 1;
    return year + "-" + (month < 10 ? "0" + month : month) + "-" + (date < 10 ? "0" + date : date);
};

//10：随机的qq [5-11]
let getRandomQQ = () => {
    //1-9
    let f = Math.floor(Math.random() * (9 - 1 + 1)) + 1;
    let st = "" + f;
    //获得随机拼接次数
    let num = Math.floor(Math.random() * (11 - 5 + 1)) + 5;
    //执行拼接操作
    for (let i = 0; i < num - 1; i++) {
        st += Math.floor(Math.random() * (10));
    }
    return st;
};

//11、专业数组
let getRandomMajor = () => {
    let major = ["web", "ui", "java", "python", "c++", "android", "ios", "windows", "linux"];
    return major[Math.floor(Math.random() * major.length)];
};

//12、获得随机的地址
let province = ["安徽省", "浙江省", "江苏省"];
let city = [
    ["合肥", "巢湖", "芜湖"],
    ["杭州", "宁波", "嘉兴"],
    ["南京", "苏州", "无锡"]
];
let district = [
    [["庐阳区", "包河区", "蜀山区"], ["ch_ro区", "ch_zt区", "ch_yu区"], ["wh_er区", "wh_qw河区", "wh_bn区"]],
    [["hz_ss区", "hz_tt区", "hz_ll区"], ["nb_kk区", "nb_yy区", "nb_ii区"], ["jx_oo区", "jx_ww区", "jx_pp区"]],
    [["nj_aa区", "nj_bb区", "nj_ff区"], ["sz_yy区", "sz_cc区", "sz_zz区"], ["wx_dd区", "wx_rr区", "wx_hh区"]],
];
let getRandomAddress = () => {
    let indexProvice = Math.floor(Math.random() * province.length);
    let pro = province[indexProvice];
    let indexCity = Math.floor(Math.random() * city[indexProvice].length);
    let a = city[indexProvice];
    let ct = a[indexCity];
    let indexDs = Math.floor(Math.random() * district[indexProvice][indexCity].length);
    let ds = district[indexProvice][indexCity][indexDs];
    return pro + "-" + ct + "-" + ds;
};

//13、获得随机的email：首字母，长度30，@ ，长度10，.一次或2次，com|cn
let getRandomEamil = () => {
    let f = arr[Math.floor(Math.random(52))];
    let st = "" + f;
    let n = Math.floor(Math.random() * (10 - 5 + 1)) + 5;
    for (let i = 0; i < n - 1; i++) {
        st += arr[Math.floor(Math.random() * (arr.length))];
    }
    st += "@";
    n = Math.floor(Math.random() * (10 - 3 + 1)) + 3;
    for (let i = 0; i < n; i++) {
        st += arr[Math.floor(Math.random() * (arr.length))];
    }
    st += ".";
    st += (Math.floor(Math.random() * 10) % 2 ? "com" : "cn");
    return st;
};




